#!/bin/bash
IBUPRO=/data/project/ibuflow/project
SERVER_IP="$(curl members.3322.org/dyndns/getip 2>/dev/null)"
FLAG=">>> # # # # # # # # # # # # # # # # # # # # # # # # # # # # # >>>"
if [ -z "$1" ] ; then
    echo "Usage:$0 {order_number} [order_date]"
    exit 1
fi
if [ -z $2 ] ; then
    order_date=3
else
    order_date=$2
fi

LOGDIR=("$IBUPRO/server-recharge-12121/logs" "$IBUPRO/server-recharge-12122/logs" "$IBUPRO/web-flow-7070/logs" "$IBUPRO/web-flow-7071/logs" )

for log in ${LOGDIR[@]}
do
    cd $log
    CMD=$(find ./ -name 'ibu-*.log' -mtime -$order_date | xargs ls -t | egrep -v "sql")
    for file in $CMD
    do
        grep --color -n -E $1 $file
        if [ $? -eq 0 ] ; then 
            echo -e "\n
\033[33m$FLAG\033[0m
\033[33m>>>\033[0m IBU-1           
\033[33m>>>\033[0m ServerIP:\033[31m $SERVER_IP \033[0m
\033[33m>>>\033[0m DirName:\033[31m $(pwd) \033[0m
\033[33m>>>\033[0m FileName:\033[31m $file \033[0m
\033[33m$FLAG\033[0m\n"
       #break
       # else
       #     echo -e "\033[33m>>>\033[0m FileName:\033[31m $file is not found.\033[0m"
        fi
    done
done
